﻿using NewsCollection.Common.Service;
using NewsCollection.Common.UpdateGUI;
using NewsCollection.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NewsCollection.ListWeb
{
    class ElleVn
    {
        // ;oad theo kieu giong trang newszing , hoac load theo kieu ngoisao,2sao 
        ProcessDb pdb = new ProcessDb();
        UpdateButton updateBtn = new UpdateButton();
        public void Run(ListView lv, Button btnStart, Button btnStop, int manuId,string folder)
        {

            Load load = new Load(lv);
            List<CategoryModel> ListCate = new List<CategoryModel>();
         

          
            //  List<Page> ListPage = new List<Page>();
            string urlGoc = "http://www.elle.vn/";


            ListCate.AddRange(load.LoadCatesWithSub(urlGoc, "//ul[@id='menu-elle-menu']//li[@id='menu-item-11855']", "//li[@id='menu-item-11855']//ul[@class='sub-menu']", "", manuId, "//li", "//a", "//a", null, false));
            ListCate.AddRange(load.LoadCatesWithSub(urlGoc, "//ul[@id='menu-elle-menu']//li[@id='menu-item-12051']", "//li[@id='menu-item-12051']//ul[@class='sub-menu']", "", manuId, "//li", "//a", "//a", null, false));
            ListCate.AddRange(load.LoadCatesWithSub(urlGoc, "//ul[@id='menu-elle-menu']//li[@id='menu-item-12057']", "//li[@id='menu-item-12057']//ul[@class='sub-menu']", "", manuId, "//li", "//a", "//a", null, false));
            ListCate.AddRange(load.LoadCatesWithSub(urlGoc, "//ul[@id='menu-elle-menu']//li[@id='menu-item-12060']", "//li[@id='menu-item-12060']//ul[@class='sub-menu']", "", manuId, "//li", "//a", "//a", null, false));
            ListCate.AddRange(load.LoadCatesWithSub(urlGoc, "//ul[@id='menu-elle-menu']//li[@id='menu-item-12066']", "//li[@id='menu-item-12066']//ul[@class='sub-menu']", "", manuId, "//li", "//a", "//a", null, false));




            int dem = 0;



            for (int i = 0; i < ListCate.Count(); i++)
            {



               //    Page lastPage = new Page();
         
              
           
                

                    
                   

                       
                      
                        var ListDetail = load.LoadUpdateNewHomeNews(ListCate[i], "//ul[@class='elle-category-list margin_bot_20']//li", "//article//a[contains(@class,'elle-collection-title')]", "", "//article//a", "");

                        
                     //   ListDetail.AddRange(load1.ListNewsDetails);
                     
                    // phai chay dong for nguoc, de xet phan tu dau tien

                        for (int k = 0; k < ListDetail.Count(); k++)
                        {
                            var item = load.LoadNews(ListDetail[k], "//div[@class='article-details-main-content']", "//div[@class='article-details-desc']//p", manuId, 0, "//div[@class='article-details-main-content']//img",urlGoc,false);
                            if (item != null)
                            {
                                
                                    dem++;

                                    load.AddItemToListView(item);

                                    pdb.SaveImgNormal(folder, item);

                                
                             
                            }
                           
                      

                           
                        }

                       
                        //if (load1.flag == true)
                        //{
                            
                        //}


                    
          
            




            }
        //    System.Windows.Forms.MessageBox.Show("\nThanh cong!Co " + dem + " tin moi");

            updateBtn.UpdateButtonStartAfterRun(btnStart);
            updateBtn.UpdateButtonStopAfterRun(btnStop);
            //updateBtn.UpdateAfterRun(btnStart,btnStop);
            //if (dem == 0)
            //{
            //    MessageBox.Show("\nKhong co san pham moi!");
            //}
            //else MessageBox.Show("\nCo "+dem + " san pham moi");






        }
    }
}
